import { queryTypeList, addType,removeType,updateType} from '@/services/system/dicType';

export default {
  namespace: 'dicType',

  state: {
    // 列表数据
    data: {
      dataList: [],
      pageNum: 0,
      pageSize: 0,
      totalCount: 0,
    },

    queryForm:{},
  },

  effects: {
    *queryList({ payload }, { call, put }) {
      const response = yield call(queryTypeList, payload);
      yield put({
        type: 'save',
        payload: response,
      });
    },
    *add({ payload, callback }, { call, put }) {
      const response = yield call(addType, payload);
      yield put({
        type: 'addData',
        payload: response,
      });
      if (callback) callback(response);
    },
    *remove({ payload, callback }, { call, put }) {
      const response = yield call(removeType, payload);
      yield put({
        type: 'deletData',
        payload: response,
      });
      if (callback) callback(response);
    },
    *update({ payload, callback }, { call, put }) {
      const response = yield call(updateType, payload);
      yield put({
        type: 'upData',
        payload: response,
      });
      if (callback) callback(response);
    },
  },

  reducers: {
    save(state, action) {
      if(action.payload.rescode == 200){
        return {
        ...state,
        data: action.payload.data,
        };
      }else{        
        alert(action.payload.msg)
        return {
        ...state,
        data: [],
        };
      }      
    },
  },
};
